package org.binglan.youziyuepai.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.binglan.youziyuepai.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.binglan.youziyuepai.vo.UserVo;

import java.util.List;

/**
 * <p>
 * 用户表 Mapper 接口
 * </p>
 *
 * @author sanjin
 * @since 2019-04-09
 */
public interface UserMapper extends BaseMapper<User> {

    /**
     * 查询用户信息
     */
    @Select("SELECT u.*,s.`name` school_name FROM `user` u,`school` s WHERE s.id=u.school_id AND u.id=#{userId}")
    UserVo queryUserVoByUserId(String userId);

    /**
     * 查询用户信息
     */
    @Select({
            "<script>",
            "select",
            "u.*, s.`name` school_name",
            "from user u, school s",
            "where s.id=u.school_id AND u.id in",
            "<foreach collection='userIds' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<UserVo> queryUserVosByUserIds(@Param("userIds") List<String> userIds);

    /**
     * 查询用户关注数量
     */
    @Select("SELECT\n" +
            "COUNT(uf.id)\n" +
            "FROM\n" +
            "\tuser_fans uf\n" +
            "\tWHERE \n" +
            "\tuf.fans_id=#{userId}")
    long queryAttentionNumByUserId(String userId);


    /**
     * 查询用户粉丝数量
     */
    @Select("SELECT\n" +
            "COUNT(uf.id)\n" +
            "FROM\n" +
            "\tuser_fans uf\n" +
            "\tWHERE \n" +
            "\tuf.user_id=#{userId}")
    long queryFansNumByUserId(String userId);
}
